<?php
//member.php

require_once 'user.php';

class Member_Dao extends User_Dao{

	function __construct(){
	}
	
	//mendapatkan seluruh data member berupa array 
	function get_all(){
		$sql="
		select *
		from
		member
		";
		
		$list_member = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$member = new Member();
				$member->id = $row['ID'];
				$member->nama= $row['NAMA'];
				$member->id_kelas = $row['ID_KELAS'];
				$member->alamat = $row['ALAMAT'];
				$member->no_telp = $row['NO_TELP'];
				$member->foto_member = $row['FOTO_MEMBER'];
				$member->fasilitas_umum = $row['FASILITAS_UMUM'];
				$member->tgl_daftar = $row['TGL_DAFTAR'];
				$member->banned = $row['BANNED'];
				
				$list_member[] = $member;
			}
		}	
		return $list_member;
	}
	
	//mendapatkan data member berupa array berdasarkan parameter id
	function get_id($id){
		$sql="
		select *
		from
		member
		WHERE
		ID = '".$id."'
		";
		
		$member=false;		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
				
				$member = new Member();
				$member->id = $row['ID'];
				$member->nama= $row['NAMA'];
				$member->id_kelas = $row['ID_KELAS'];
				$member->alamat = $row['ALAMAT'];
				$member->no_telp = $row['NO_TELP'];
				$member->foto_member = $row['FOTO_MEMBER'];
				$member->fasilitas_umum = $row['FASILITAS_UMUM'];
				$member->tgl_daftar = $row['TGL_DAFTAR'];
				$member->banned = $row['BANNED'];
			}
		}	
		return $member;
	}
	
	//menmbahkan data member
	function add_member(Member $member){
		$sql="insert 
		into 
		member
		values(
		'$member->id',
		'$member->nama',
		'$member->id_kelas',
		'$member->alamat', 
		'$member->no_telp', 
		'',
		'$member->fasilitas_umum',
		'$member->tgl_daftar',
		'$member->banned')
		";
		$query=mysql_query($sql);
	}
	
	//mengubah data member
	function edit(Member $member){
		$sql="
		update 
		member 
		set 
		NAMA='$member->nama',
		ID_KELAS='$member->id_kelas',
		ALAMAT='$member->alamat',
		NO_TELP='$member->no_telp',
		FASILITAS_UMUM='$member->fasilitas_umum'
		where ID='$member->id'
		";
		$query=mysql_query($sql);
	}
	
	function edit_gambar(Member $member){
		$sql="
		update 
		member 
		set 
		FOTO_MEMBER='$member->foto_member'
		where ID='$member->id'
		";
		$query=mysql_query($sql);
	}
	
	function banned(Member $member){
		$sql="
		update 
		member 
		set 
		BANNED='".$member->banned."'
		where ID='".$member->id."'
		";
		$query=mysql_query($sql);
		
	}
	
	//mendapatkan data member berdasarkan parameter id_kelas
	function get_kelas($id_kelas){
		$sql="
		select *
		from
		member
		where
		ID_KELAS = '".$id_kelas."'
		";
		
		$list_member = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$member = new Member();
				$member->id = $row['ID'];
				$member->nama= $row['NAMA'];
				$member->id_kelas = $row['ID_KELAS'];
				$member->alamat = $row['ALAMAT'];
				$member->no_telp = $row['NO_TELP'];
				$member->foto_member = $row['FOTO_MEMBER'];
				$member->fasilitas_umum = $row['FASILITAS_UMUM'];
				$member->tgl_daftar = $row['TGL_DAFTAR'];
				$member->banned = $row['BANNED'];
				
				$list_member[] = $member;
			}
		}	
		return $list_member;
	}
	
	//mendapatkan data member berdasarkan parameter alamat
	function get_alamat($alamat){
		$sql="
		select *
		from
		member
		where
		ALAMAT LIKE '%".$alamat."%'
		";
		
		$list_member = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$member = new Member();
				$member->id = $row['ID'];
				$member->nama= $row['NAMA'];
				$member->id_kelas = $row['ID_KELAS'];
				$member->alamat = $row['ALAMAT'];
				$member->no_telp = $row['NO_TELP'];
				$member->foto_member = $row['FOTO_MEMBER'];
				$member->fasilitas_umum = $row['FASILITAS_UMUM'];
				$member->tgl_daftar = $row['TGL_DAFTAR'];
				$member->banned = $row['BANNED'];
				
				$list_member[] = $member;
			}
		}	
		return $list_member;
	}
	
	//mendapatkan data member berdasarkan parameter id_kelas dan alamat
	function get_kelat($id_kelas, $alamat){
		$sql="
		select *
		from
		member
		where
		ID_KELAS = '".$id_kelas."' AND 
		ALAMAT LIKE '%".$alamat."%'
		";
		
		$list_member = array();
		
		$data = mysql_query($sql);
		if($data){
			while($row = mysql_fetch_assoc($data)){
			
				$member = new Member();
				$member->id = $row['ID'];
				$member->nama= $row['NAMA'];
				$member->id_kelas = $row['ID_KELAS'];
				$member->alamat = $row['ALAMAT'];
				$member->no_telp = $row['NO_TELP'];
				$member->foto_member = $row['FOTO_MEMBER'];
				$member->fasilitas_umum = $row['FASILITAS_UMUM'];
				$member->tgl_daftar = $row['TGL_DAFTAR'];
				$member->banned = $row['BANNED'];
				
				$list_member[] = $member;
			}
		}	
		return $list_member;
	}

}

class Member extends User{
	//var $id;
	var $nama;
	var $id_kelas;
	var $alamat;
	var $no_telp;
	var $foto_member;
	var $fasilitas_umum;
	var $tgl_daftar;
	var $banned;

}